<?php

	function captcha_create($registration_details){
		global $main_smarty, $the_template;

		if(!isset($_SESSION)){session_start();}
		unset($_SESSION['security_code']);

		$reghash = generateHash(rand(10000000, 99999999));
		$main_smarty->assign('reghash', $reghash);
		$_SESSION['reghash'] = $reghash;

		$main_smarty->assign('ts_random', rand(10000000, 99999999));

		$register_step_1_extra = $main_smarty->get_template_vars('register_step_1_extra');
		$register_step_1_extra .= $main_smarty->fetch(captcha_captchas_path . '/default/captcha.tpl');
		$main_smarty->assign('register_step_1_extra', $register_step_1_extra);

	}

	function captcha_check($registration_details){
		global $main_smarty, $the_template;

		if(!isset($_SESSION)){session_start();}

		$username = $registration_details['username'];
		$email = $registration_details['email'];
		$password = $registration_details['password'];

		if (!ts_is_human() || $_POST["reghash"] != $_SESSION['reghash']){ // if incorrect captcha code was entered

			$main_smarty->assign('register_captcha_error', "The answer provided is not correct. Please try again.");

			return false;

		} else {

			return true;
		}

	}

	function captcha_configure(){
		// there is nothing to configure for this captcha
	}

	function captcha_can_we_use(){
		// nothing special is needed for this captcha
		return true;
	}
?>
